﻿package mortal.game.view.mainUI.rightTop
{
    import Message.Public.*;
    import com.gengine.global.*;
    import com.greensock.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;
    import mortal.common.global.*;
    import mortal.common.sound.*;
    import mortal.common.swfPlayer.*;
    import mortal.common.swfPlayer.data.*;
    import mortal.game.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.view.common.*;
    import mortal.game.view.mail.view.*;
    import mortal.game.view.systemSetting.*;
    import mortal.mvc.core.*;

    public class MapNavBarModule extends View
    {
        private var _mainContainer:GSprite;
        private var _bg:GBitmap;
        private var _btn:GLoadedButton;
        private var _txt:GTextFiled;
        private var _btnMail:GLoadedButton;
        private var _btnSysSetting:GLoadedButton;
        private var _btnAutoFight:GLoadedButton;
        private var _btnlock:GLoadedButton;
        private var _btnVoice:GLoadedButton;
        private var _btnCloseAndOpenContainer:GSprite;
        private var _btnClose:GLoadedButton;
        private var _btnOpen:GLoadedButton;
        private var _btnHideContianer:GSprite;
        private var _btnHide0:GLoadedButton;
        private var _btnHide1:GLoadedButton;
        private var _btnHide2:GLoadedButton;
        private var _rightTopModule:RightTopBar;
        private var _swfPlayer:SWFPlayer;

        public function MapNavBarModule()
        {
            this.layer = LayerManager.uiLayer;
            this.mouseEnabled = false;
            return;
        }// end function

        public function get rightTopBar() : RightTopBar
        {
            return this._rightTopModule;
        }// end function

        override protected function configUI() : void
        {
            super.configUI();
            this._mainContainer = UIFactory.getUICompoment(GSprite, 0, 0, this);
            this._btnCloseAndOpenContainer = UIFactory.getUICompoment(GSprite, -34, 0, this);
            this._btnOpen = UIFactory.gLoadedButton(ImagesConst.ui_mapUIOpen_upSkin, 0, 0, 21, 20, this._btnCloseAndOpenContainer);
            this._btnClose = UIFactory.gLoadedButton(ImagesConst.ui_mapUIClose_upSkin, 0, 0, 21, 20, this._btnCloseAndOpenContainer);
            this._btnOpen.toolTipData = Language.getString(35365);
            this._btnClose.toolTipData = Language.getString(35366);
            this._bg = UIFactory.gBitmap(ImagesConst.MapRightTop_bg, -266, 0, this._mainContainer);
            this._btn = UIFactory.gLoadedButton(ImagesConst.MapBall_upSkin, -93, 9, 64, 63, this._mainContainer);
            var _loc_1:* = GlobalStyle.textFormatPutong;
            _loc_1.align = TextFormatAlign.CENTER;
            this._txt = UIFactory.gTextField("", -250, 26, 150, 20, this._mainContainer, _loc_1);
            this._btnVoice = UIFactory.gLoadedButton(ImagesConst.soundOpen_upSkin, -30, 45, 25, 25, this._mainContainer);
            this._btnVoice.toolTipData = Language.getString(35367);
            this._btnSysSetting = UIFactory.gLoadedButton(ImagesConst.ui_sysSetting_upSkin, -45, 66, 28, 28, this._mainContainer);
            this._btnSysSetting.toolTipData = Language.getString(35368);
            this._btnHideContianer = UIFactory.getUICompoment(GSprite, -113, 53, this._mainContainer);
            this._btnHide0 = UIFactory.gLoadedButton(ImagesConst.ui_hide0_upSkin, 0, 0, 25, 25, this._btnHideContianer);
            this._btnHide1 = UIFactory.gLoadedButton(ImagesConst.ui_hide1_upSkin, 0, 0, 25, 25, this._btnHideContianer);
            this._btnHide2 = UIFactory.gLoadedButton(ImagesConst.ui_hide2_upSkin, 0, 0, 25, 25, this._btnHideContianer);
            this._btnHide0.toolTipData = Language.getString(35369);
            this._btnHide1.toolTipData = Language.getString(35369);
            this._btnHide2.toolTipData = Language.getString(35369);
            this._btnHide1.visible = false;
            this._btnHide2.visible = false;
            this._btnHideContianer.configEventListener(MouseEvent.CLICK, this.onClickContainnerEffect);
            this._btnAutoFight = UIFactory.gLoadedButton(ImagesConst.ui_autoFight_upSkin, -70, 74, 25, 25, this._mainContainer);
            this._btnAutoFight.toolTipData = Language.getString(35370);
            this._btnMail = UIFactory.gLoadedButton(ImagesConst.uiMail_upSkin, -26, 18, 25, 25, this._mainContainer);
            this._btnMail.toolTipData = Language.getString(35371);
            this.configEventListener(MouseEvent.CLICK, this.onMouseClick);
            NetDispatcher.addCmdListener(ServerCommand.MailNotice, this.onNewMail);
            this.updateBtnHideVisible();
            this.onNewMail(null);
            this.updateVoiceStyle();
            Dispatcher.addEventListener(EventName.ForbitMusicChange, this.updateVoiceStyle);
            this._rightTopModule = UICompomentPool.getUICompoment(RightTopBar);
            this._rightTopModule.x = -248;
            this._rightTopModule.y = 51;
            this._mainContainer.addChild(this._rightTopModule);
            return;
        }// end function

        private function onNewMail(param1:Object) : void
        {
            if (Cache.instance.mail.mailNotice)
            {
                if (!this._swfPlayer)
                {
                    this._swfPlayer = UIFactory.getUICompoment(SWFPlayer);
                    this._swfPlayer.timeRate = 2;
                    this._swfPlayer.move(12, 10);
                    this._swfPlayer.load("IconFlashs.swf", ModelType.NormalSwf, null);
                }
                this._btnMail.addChild(this._swfPlayer);
                MailHintIcon.instance.show();
            }
            else
            {
                MailHintIcon.instance.hide();
                EffectManager.glowFilterUnReg(this._btnMail);
                if (this._swfPlayer)
                {
                    this._swfPlayer.dispose();
                    this._swfPlayer = null;
                }
            }
            return;
        }// end function

        private function updateVoiceStyle(event:Event = null) : void
        {
            if (SystemSetting.instance.isForbidMusic.displayValue)
            {
                this._btnVoice.styleName = ImagesConst.soundClose_upSkin;
            }
            else
            {
                this._btnVoice.styleName = ImagesConst.soundOpen_upSkin;
            }
            this.updateBgMusic();
            this.updateEffectMusic();
            return;
        }// end function

        protected function updateBgMusic() : void
        {
            SoundManager.instance.musicVolume = SystemSetting.instance.isForbidMusic.displayValue ? (0) : (int(SystemSetting.instance.bgMusic.displayValue) / 100);
            return;
        }// end function

        protected function updateEffectMusic() : void
        {
            SoundManager.instance.effectSoundVolune = SystemSetting.instance.isForbidMusic.displayValue ? (0) : (int(SystemSetting.instance.effectMusic.displayValue) / 100);
            return;
        }// end function

        public function updateBtnHideVisible() : void
        {
            this.updateVoiceStyle();
            switch(SystemSetting.instance.hideSetter.value)
            {
                case 0:
                {
                    this.hideOtherButton(this._btnHideContianer, this._btnHide0);
                    break;
                }
                case 1:
                {
                    this.hideOtherButton(this._btnHideContianer, this._btnHide1);
                    break;
                }
                case 2:
                {
                    this.hideOtherButton(this._btnHideContianer, this._btnHide2);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function updateToCurrent(param1:SPoint = null) : void
        {
            if (Game.mapInfo == null)
            {
                return;
            }
            var _loc_2:* = GameMapConfig.instance.getMapInfo(Game.mapInfo.mapId).name;
            this._txt.text = _loc_2;
            return;
        }// end function

        private function onClickContainnerEffect(event:MouseEvent) : void
        {
            var _loc_2:Point = null;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            if (QuickHideSetPanel.instance.isHide)
            {
                _loc_2 = this._btnHideContianer.localToGlobal(new Point(0, 0));
                _loc_3 = _loc_2.x - 213;
                _loc_4 = _loc_2.y;
                QuickHideSetPanel.instance.show(_loc_3, _loc_4);
                Global.stage.addEventListener(MouseEvent.CLICK, this.onClickStage);
            }
            else
            {
                QuickHideSetPanel.instance.hide();
                Global.stage.removeEventListener(MouseEvent.CLICK, this.onClickStage);
            }
            return;
        }// end function

        private function onClickStage(event:MouseEvent) : void
        {
            var _loc_2:* = event.target as DisplayObject;
            if (_loc_2 != this._btnHideContianer && !this._btnHideContianer.contains(_loc_2) && _loc_2 != QuickHideSetPanel.instance && !QuickHideSetPanel.instance.contains(_loc_2))
            {
                QuickHideSetPanel.instance.hide();
                Global.stage.removeEventListener(MouseEvent.CLICK, this.onClickStage);
            }
            return;
        }// end function

        private function onMouseClick(event:MouseEvent) : void
        {
            switch(event.target)
            {
                case this._btnOpen:
                {
                    this.hideOtherButton(this._btnCloseAndOpenContainer, this._btnClose);
                    TweenMax.to(this._mainContainer, 0.2, {y:0});
                    break;
                }
                case this._btnClose:
                {
                    this.hideOtherButton(this._btnCloseAndOpenContainer, this._btnOpen);
                    TweenMax.to(this._mainContainer, 0.2, {y:-this.height});
                    break;
                }
                case this._btnMail:
                {
                    GameManager.instance.popupModuleType(ModuleType.Mail);
                    break;
                }
                case this._btn:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.SmallMapShowHide));
                    break;
                }
                case this._btnVoice:
                {
                    if (this._btnVoice.styleName == ImagesConst.soundOpen_upSkin)
                    {
                        SystemSetting.instance.isForbidMusic.value = 1;
                    }
                    else
                    {
                        SystemSetting.instance.isForbidMusic.value = 0;
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ForbitMusicChange, SystemSetting.instance.isForbidMusic.displayValue));
                    SystemSetting.instance.save();
                    break;
                }
                case this._btnlock:
                {
                    break;
                }
                case this._btnSysSetting:
                {
                    GameManager.instance.popupModuleType(ModuleType.SysSet);
                    break;
                }
                case this._btnAutoFight:
                {
                    GameManager.instance.popupModuleType(ModuleType.AutoFightView);
                    break;
                }
                case this._btnHide0:
                case this._btnHide1:
                case this._btnHide2:
                {
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        override public function stageResize() : void
        {
            this.x = SceneRange.display.width;
            this.y = 0;
            return;
        }// end function

        private function hideOtherButton(param1:GSprite, param2:GLoadedButton) : void
        {
            var _loc_3:GLoadedButton = null;
            var _loc_4:int = 0;
            while (_loc_4 < param1.numChildren)
            {
                
                _loc_3 = param1.getChildAt(_loc_4) as GLoadedButton;
                if (_loc_3 && _loc_3 != param2)
                {
                    _loc_3.visible = false;
                }
                _loc_4++;
            }
            param2.visible = true;
            return;
        }// end function

    }
}
